package com.techusn.json.fromat.base.strategy.factory;

import com.techusn.json.fromat.base.strategy.FormatStrategy;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenYX
 * @date 2021/8/13 10:33
 * @description
 */
public class FormatStrategyFactory {

    /**
     * format策略集合
     */
    private static final Map<String, FormatStrategy<?,?>> STRATEGY_MAP = new HashMap<>();

    /**
     *
     * @author : yongxiang
     * @description： 添加策略
     * @param
     * @date : 10:35 2021/8/13
    */
    public static void putStrategy(String key,FormatStrategy<?,?> formatStrategy){
        if (StringUtils.isNotBlank(key) && formatStrategy != null){
            STRATEGY_MAP.put(key,formatStrategy);
        }
    }


    /**
     *
     * @author : yongxiang
     * @description: 获取策略依据key
     * @param key key
     * @date : 10:38 2021/8/13
    */
    public static FormatStrategy<?,?> getStrategy(String key){
        if (StringUtils.isNotBlank(key)){
            return STRATEGY_MAP.get(key);
        }
        return null;
    }

    /**
     *
     * @author : yongxiang
     * @description: 是否是合法的key
     * @param key key
     * @date : 10:40 2021/8/13
    */
    public static boolean isValidKey(String key){
        return StringUtils.isNotBlank(key) && !STRATEGY_MAP.containsKey(key);
    }

}
